Example Class Used Throughout Examples
These are just generic (Nier based) classes I made for testing a few classes!
public class Operation
{
public string OperationName { get; set; }
public string Description { get; set; }
public string YorhaSect { get; set; }
public List<Operator> Operators { get; set; } // Changed to Operator class for more detailed information
public Dictionary<string, string>? ATypeOperators { get; set; }
public Dictionary<string, string>? BTypeOperators { get; set; }
public Dictionary<string, string>? DTypeOperators { get; set; }
public Dictionary<string, string>? ETypeOperators { get; set; }
public Dictionary<string, string>? GTypeOperators { get; set; }
public Dictionary<string, string>? HTypeOperators { get; set; }
public Dictionary<string, string>? OTypeOperators { get; set; }
public Dictionary<string, string>? STypeOperators { get; set; }
// New types based on the Nier universe
public List<Enemy> Enemies { get; set; }
public List<Weapon> Weapons { get; set; }
// Adding more test values
public bool IsActive { get; set; }
public int MaxLevel { get; set; }
public double Difficulty { get; set; }
public float AttackSpeed { get; set; }
public DateTime CreatedAt { get; set; }
public Operation()
{
// Test Data
OperationName = "Operation 1";
Description = "This is a test operation.";
YorhaSect = "Sect A";
// Nier-based Operators with nicknames
Operators = new List<Operator>
{
new Operator { Name = "2B", Nickname = "The Silent Protector", Role = "Attacker" },
new Operator { Name = "9S", Nickname = "The Curious Hacker", Role = "Support" },
new Operator { Name = "A2", Nickname = "The Lone Wolf", Role = "Assault" },
new Operator { Name = "9S (Scanner)", Nickname = "The Investigator", Role = "Recon" },
new Operator { Name = "3C", Nickname = "The Stealth Specialist", Role = "Stealth" }
};
ATypeOperators = new Dictionary<string, string>
{
{ "A1", "2B" },
{ "A2", "9S" }
};
BTypeOperators = new Dictionary<string, string>
{
{ "B1", "A2" },
{ "B2", "9S" }
};
DTypeOperators = new Dictionary<string, string>
{
{ "D1", "A2" },
{ "D2", "2B" }
};
ETypeOperators = new Dictionary<string, string>
{
{ "E1", "Yonah" },
{ "E2", "Emil" }
};
GTypeOperators = new Dictionary<string, string>
{
{ "G1", "Kaine" },
{ "G2", "Devola" }
};
HTypeOperators = new Dictionary<string, string>
{
{ "H1", "Adam" },
{ "H2", "Eve" }
};
OTypeOperators = new Dictionary<string, string>
{
{ "O1", "Pascal" },
{ "O2", "Yonah" }
};
STypeOperators = new Dictionary<string, string>
{
{ "S1", "Nier" },
{ "S2", "Nier (Older)" }
};
// Initialize the new Nier-based properties
Enemies = new List<Enemy>
{
new Enemy { EnemyName = "Machine A", EnemyType = "Type 1", Health = 100, Attack = 25, IsBoss = false },
new Enemy { EnemyName = "Machine B", EnemyType = "Type 2", Health = 200, Attack = 50, IsBoss = true },
new Enemy { EnemyName = "Machine C", EnemyType = "Type 3", Health = 300, Attack = 75, IsBoss = false }
};
Weapons = new List<Weapon>
{
new Weapon { WeaponName = "Sword", WeaponType = "Close Range", Damage = 150, Weight = 5.5f, IsLegendary = false },
new Weapon { WeaponName = "Gun", WeaponType = "Long Range", Damage = 100, Weight = 3.2f, IsLegendary = true }
};
// Additional testing fields
IsActive = true;
MaxLevel = 99;
Difficulty = 2.5; // A value from 1 to 5
AttackSpeed = 1.25f;
CreatedAt = DateTime.Now;
}
}
public class Operator
{
public string Name { get; set; }
public string Nickname { get; set; }
public string Role { get; set; }
}
public class Enemy
{
public string EnemyName { get; set; }
public string EnemyType { get; set; }
public int Health { get; set; }
public int Attack { get; set; }
public bool IsBoss { get; set; } // Indicates if the enemy is a boss
}
public class Weapon
{
public string WeaponName { get; set; }
public string WeaponType { get; set; }
public int Damage { get; set; }
public float Weight { get; set; } // Weight in kilograms
public bool IsLegendary { get; set; } // Indicates if the weapon is legendary
}
public async Task<byte[]> ToByte()
{
return await BinaryConverter.ObjectToByteArrayAsync("This is a test string.");
}
public async Task<string> FromByte(byte[] byteArray)
{
return await BinaryConverter.ByteArrayToObjectAsync<string>(byteArray);
}
public async void TestObjectToByteArrayAsync()
{
BinaryConverter binaryConverter = new BinaryConverter();
Operation operation = new Operation();
// Convert the operation object to a byte array
byte[] byteArray = await BinaryConverter.ObjectToByteArrayAsync(operation);
Console.WriteLine("Byte array length: " + byteArray.Length);
// Convert the byte array back to an object
Operation convertedOperation = await BinaryConverter.ByteArrayToObjectAsync<Operation>(byteArray);
Console.WriteLine("Converted Operation Name: " + convertedOperation.OperationName);
Console.WriteLine("Converted Description: " + convertedOperation.Description);
Console.WriteLine("Converted Yorha Sect: " + convertedOperation.YorhaSect);
Console.WriteLine("Converted IsActive: " + convertedOperation.IsActive);
Console.WriteLine("Converted MaxLevel: " + convertedOperation.MaxLevel);
Console.WriteLine("Converted Difficulty: " + convertedOperation.Difficulty);
Console.WriteLine("Converted AttackSpeed: " + convertedOperation.AttackSpeed);
Console.WriteLine("Converted CreatedAt: " + convertedOperation.CreatedAt);
Console.WriteLine("Converted Operators Count: " + convertedOperation.Operators.Count);
Console.WriteLine("Converted Enemies Count: " + convertedOperation.Enemies.Count);
Console.WriteLine("Converted Weapons Count: " + convertedOperation.Weapons.Count);
//Newline spacer
Console.WriteLine(Environment.NewLine);
Console.WriteLine(Environment.NewLine);
}